/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mindwave.theoracle;

/**
 *
 * @author lorenzo
 */
import java.awt.*;
import javax.swing.*;

public class Grafics extends JFrame /*WindowListener,*/ {

    public JLabel image1 = new JLabel();
    public JLabel image2 = new JLabel();
    public JLabel image3 = new JLabel();
    public JLabel image4 = new JLabel();
    JTextField tf = new JTextField();
    private JPanel basic = new JPanel();
    final int width = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    final int height = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    private boolean ready = false;
    private String Name = "defaultUser";

    public boolean isReady() {
        return ready;
    }

    public Grafics(int idframe) {
        //super("MINDWAVE THE ORACLE");
        if (idframe == 1) {
            this.setSize(900, 400);
            //this.setLocation(100, 100);
            this.setResizable(false);

            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.deffin();
        }
        if (idframe == 2) {
            setUndecorated(true);

            setSize(width, height);

            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.deffin2();

        }
        if (idframe == 3) {
            setSize(width, height);
            this.deffin3();
        }



    }

    public void deffin() {
        JPanel basic = new JPanel();
        basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
        basic.setBackground(new Color(204, 255, 204));
        add(basic);

        basic.add(Box.createVerticalGlue());

        JPanel bottom = new JPanel();
        bottom.setAlignmentX(1f);
        bottom.setBackground(new Color(204, 255, 204));
        //addWindowListener (this);
        bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
        JLabel training = new JLabel("MINDWAVE TRAINING");
        training.setForeground(Color.BLUE);
        training.setBackground(new Color(204, 255, 204));
        JButton inizia = new JButton("inizia");
        inizia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button(1);
            }
        });

        inizia.setForeground(Color.BLUE);
        inizia.setBackground(new Color(204, 255, 204));





        bottom.add(training);
        bottom.add(Box.createRigidArea(new Dimension(60, 0)));
        bottom.add(inizia);
        bottom.add(Box.createRigidArea(new Dimension(10, 0)));
        basic.add(bottom);
        basic.add(Box.createRigidArea(new Dimension(0, 15)));

        setTitle("MINDWAVE THE ORACLE");
        setSize(300, 150);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);



    }

    public void deffin2() {



        basic.setBackground(Color.white);
        basic.setBounds(0, 0, width, height);
        basic.setLayout(null);
        tf = new JTextField();
        tf.setEditable(true);
        JLabel next = new JLabel("Inserisci il nome nella casella poi scegli un immagine e memorizzala");
        tf.setBounds((width / 2 - 75), 250, 150, 50);
        tf.setFont(new Font(null, Font.BOLD, 20));
        JButton close = new JButton("Chiudi");
        next.setBounds((width / 2 - 320), 200, 640, 30);
        java.awt.Font font = new java.awt.Font("Dialog", Font.BOLD, 20);
        next.setFont(font);
        next.setForeground(Color.BLACK);
        close.setBounds((width - 100), 0, 100, 50);
        close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button(2);
            }
        });

        //Container c = this.getContentPanel(); 

        //definisco la variabile width per dividere lo schermo in 4
        int widthimage = ((width / 4) / 2);
        //carico l'immagine nella label
        //bisognerebbe gestire l'eccezione se manca l'immagine
        Icon image1 = new ImageIcon(getClass().getResource("images/Immagine1A.jpg"));
        JLabel Limage1 = new JLabel(image1);
        Limage1.setBounds((widthimage - 105), (height / 2), 210, 210);
        Icon image2 = new ImageIcon(getClass().getResource("images/Immagine2A.jpg"));
        JLabel Limage2 = new JLabel(image2);
        Limage2.setBounds((widthimage * 3 - 105), (height / 2), 210, 210);
        Icon image3 = new ImageIcon(getClass().getResource("images/Immagine3A.jpg"));
        JLabel Limage3 = new JLabel(image3);
        Limage3.setBounds((widthimage * 5 - 105), (height / 2), 210, 210);
        Icon image4 = new ImageIcon(getClass().getResource("images/Immagine4A.jpg"));
        JLabel Limage4 = new JLabel(image4);
        Limage4.setBounds((widthimage * 7 - 105), (height / 2), 210, 210);

        //faccio il bottone per il next frame
        JButton Predictor = new JButton("INDOVINA");
        Predictor.setBounds(width / 2 - 50, height - 50, 100, 50);
        Predictor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                if (tf.getText().toCharArray().length != 0 && !tf.getText().equals("Inserire Nome!!")) {
                    button(3);
                    ready = true;
                    Name = tf.getText();
                } else {
                    tf.setText("Inserire Nome!!");
                }

            }
        });

        //carico tutto sul frame
        basic.add(tf);
        basic.add(close);
        basic.add(next);
        basic.add(Limage1);
        basic.add(Limage2);
        basic.add(Limage3);
        basic.add(Limage4);
        basic.add(Predictor);
        this.add(basic);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        basic.setVisible(true);



    }

    public void deffin3() {


   basic.setVisible(false);
        JPanel orac = new JPanel();
        orac.setBackground(Color.white);
        orac.setBounds(0, 0, width, height);
        orac.setLayout(null);
        this.add(orac);
        Icon iimage1 = new ImageIcon(getClass().getResource("images/Immagine1S.jpg"));
        image1.setIcon(iimage1);
        image1.setBounds(width / 4 - 105, height / 4 - 105, 210, 210);
        Icon iimage2 = new ImageIcon(getClass().getResource("images/Immagine2S.jpg"));
        image2.setIcon(iimage2);
        image2.setBounds((width / 4)*3 - 105, height / 4 - 105, 210, 210);
        Icon iimage3 = new ImageIcon(getClass().getResource("images/Immagine3S.jpg"));
        image3.setIcon(iimage3);
        image3.setBounds(width / 4 - 105, (height / 4)*3 - 105, 210, 210);
        Icon iimage4 = new ImageIcon(getClass().getResource("images/Immagine4S.jpg"));
        image4.setIcon(iimage4);
        image4.setBounds((width / 4)*3 - 105, (height / 4)*3 - 105, 210, 210);
        orac.add(image1);
        orac.add(image2);
        orac.add(image3);
        orac.add(image4);
        

    }

    public String getName() {
        return this.Name;
    }

    public void button(int id) {
        if (id == 1) {
            Grafics g = new Grafics(2);
        }

        if (id == 2) {
            System.exit(0);

        }
        if (id == 3) {

            deffin3();
        }
    }

  public static void main(String args[]) {
        new Grafics(2);
    }
  
  public void setImageFig(int num, Icon ic){
      
      switch (num){
          case 1: image1.setIcon(ic);break;
          case 2: image2.setIcon(ic);break;
          case 3: image3.setIcon(ic);break;
          case 4: image4.setIcon(ic);break;
      }
  }

}


